﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IBLL;
using PageEntity;
using UnitWorkContext;
using OA.DataBase;
using EntityModel;

namespace BLLImp
{
    public class SysActionServer : ISysActionServer
    {
        public DataGridDTO LoadSysActionForPage(PageEntity.PagerDTO page)
        {
            DataGridDTO result = new DataGridDTO();
            IEnumerable<SysAction> sysActions;
            using (IUnitOfWork unitwork = new UnitOfWork(new OAContext()))
            {
                sysActions = unitwork.SysActionRepository.All().Skip((page.Page - 1) * page.Rows).Take(page.Rows);
                result.total = unitwork.SysActionRepository.All().Count();
            }
            result.rows = sysActions;
            return result;
        }

        public SysActionDTO Save(SysActionDTO mode)
        {
            SysAction _mode = new SysAction()
            {
                SysActionName = mode.SysActionName,
                IcoUrl = mode.IcoUrl,
                CheckInTime = DateTime.Now,
                State = true

            };

            using (IUnitOfWork unitwork = new UnitOfWork(new OAContext()))
            {
                unitwork.SysActionRepository.Insert(_mode);
                mode.SysActionID = _mode.SysActionID;
                unitwork.Save();
                return mode;
            }
        }

        public bool Delet(SysActionDTO mode)
        {
            using (IUnitOfWork unitwork = new UnitOfWork(new OAContext()))
            {
                SysAction _mode = new SysAction()
                {
                    SysActionID = mode.SysActionID
                };
                unitwork.SysActionRepository.Delet(_mode);
                unitwork.Save();
                return true;

            }
        }
    }
}
